package com.emmmya.harinCheck.engine.utils;

import com.emmmya.harinCheck.engine.HarinCheckEngine;
import com.emmmya.harinCheck.engine.impl.DefaultHarinCheckEngine;
import com.emmmya.harinCheck.exception.HarinCheckException;
import com.emmmya.harinCheck.pojo.TestEntity;
import com.emmmya.harinCheck.result.CheckResult;

import java.lang.reflect.Method;

/**
 * @author Harin
 * @version 1.0
 * @date 2022-05-05 17:54:11
 */
public class DefaultCheckUtils {
    public static CheckResult check(HarinCheckEngine engine,Object obj) throws IllegalAccessException {
        return check(engine,obj,null);
    }

    public static CheckResult check(HarinCheckEngine engine,Object obj,String[] fieldNames) throws IllegalAccessException {
        return engine.check(obj,fieldNames);
    }

    public static CheckResult check(HarinCheckEngine engine,Object obj,String[] fieldNames,Boolean deep) throws IllegalAccessException {
        return engine.check(obj,fieldNames,deep);
    }

    public static CheckResult check(Class clazz,Object obj) throws IllegalAccessException, InstantiationException,HarinCheckException {
        boolean flag = HarinCheckEngine.class.isAssignableFrom(clazz);
        if(flag){
            HarinCheckEngine engine = (HarinCheckEngine)clazz.newInstance();
            return check(engine,obj,null);
        }
        throw new HarinCheckException("传入的引擎类没有实现接口：com.emmmya.harinCheck.engine.HarinCheckEngine");
    }

    public static CheckResult check(Class clazz,Object obj,Boolean depp) throws IllegalAccessException, InstantiationException,HarinCheckException {
        boolean flag = HarinCheckEngine.class.isAssignableFrom(clazz);
        if(flag){
            HarinCheckEngine engine = (HarinCheckEngine)clazz.newInstance();
            return check(engine,obj,null,depp);
        }
        throw new HarinCheckException("传入的引擎类没有实现接口：com.emmmya.harinCheck.engine.HarinCheckEngine");

    }

    public static CheckResult check(Class clazz,Object obj,String[] fieldNames) throws IllegalAccessException, InstantiationException,HarinCheckException {
        boolean flag = HarinCheckEngine.class.isAssignableFrom(clazz);
        if(flag){
            HarinCheckEngine engine = (HarinCheckEngine)clazz.newInstance();
            return check(engine,obj,fieldNames);
        }
        throw new HarinCheckException("传入的引擎类没有实现接口：com.emmmya.harinCheck.engine.HarinCheckEngine");

    }


}
